/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.sadhar.sipp.supplier;

import org.sadhar.sipp.perekamankodeglsupplier.*;
import org.sadhar.sia.framework.ClassApplicationModule;
import org.zkoss.zul.Label;
import org.zkoss.zul.Listbox;
import org.zkoss.zul.Listcell;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Textbox;
import org.zkoss.zul.Window;

/**
 *
 * @author hendro
 */
public class SupplierPopupWnd extends ClassApplicationModule {

    private Textbox txtboxKeySearch;
    private Listbox lstboxDaftarSupplier;
    private PerekamanKodeGLSupplierDAO supplierDAO;

    public SupplierPopupWnd() {
        this.supplierDAO = new PerekamanKodeGLSupplierDAOImpl();
    }

    public void onCreate() throws Exception {
        txtboxKeySearch = (Textbox) getFellow("txtboxKeySearch");
        lstboxDaftarSupplier = (Listbox) getFellow("lstboxDaftarSupplier");
        load();
    }

    public void load() throws Exception {
        lstboxDaftarSupplier.getItems().clear();
        int no = 1;
        for (PerekamanKodeGLSupplier supplier : supplierDAO.list(txtboxKeySearch.getValue().toString())) {
            Listitem item = new Listitem();
            item.setValue(supplier);
            item.appendChild(new Listcell("" + no++));
            item.appendChild(new Listcell(supplier.getNamaSupplier()));
            item.appendChild(new Listcell(supplier.getAlamat()));
            item.appendChild(new Listcell(supplier.getTelp()));
            lstboxDaftarSupplier.appendChild(item);
        }
    }

    public void lstboxDaftarSupplierOnSelect() {
        Window window = (Window) this.getRoot().getFellow("contentDiv").getFirstChild();
        Label lblNama = (Label) window.getFellow("lblNama");
        Label lblAlamat = (Label) window.getFellow("lblAlamat");
        Label lblTelp = (Label) window.getFellow("lblTelp");
        Textbox txtboxKodeGLSupplier = (Textbox) window.getFellow("txtboxKodeGLSupplier");
        Textbox txtboxKodeSupplier = (Textbox) window.getFellow("txtboxKodeSupplier");
        
        PerekamanKodeGLSupplier supplier = (PerekamanKodeGLSupplier) lstboxDaftarSupplier.getSelectedItem().getValue();
        lblNama.setValue(supplier.getNamaSupplier());
        lblTelp.setValue(supplier.getTelp());
        lblAlamat.setValue(supplier.getAlamat());
        txtboxKodeGLSupplier.setValue(supplier.getKodeGLSupplier());
        txtboxKodeSupplier.setValue(supplier.getKodeSupplier()+"");
        this.detach();
    }
}
